package com.liliudong.keelflower.upms.biz.entity.sys;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.liliudong.keelflower.common.core.utils.validation.Insert;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 系统用户
 * </p>
 *
 * @author liudong.li
 * @since 2021-06-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_user")
@ApiModel(value = "系统用户")
public class SysUser implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 登录用户名
     */
    @ApiModelProperty(value = "登录用户名")
    @NotBlank(message = "用户名不能为空", groups = {Insert.class})
    private String username;

    /**
     * 真实姓名
     */
    @ApiModelProperty(value = "真实姓名")
    private String realName;

    /**
     * 昵称
     */
    private String nickname;

    /**
     * 头像
     */
    private String headImg;

    /**
     * 性别 0.未知 1.男 2.女
     */
    private Integer sex;

    /**
     * 手机号
     */
    private String mobile;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空", groups = {Insert.class})
    @Length(min = 6, max = 18, message = "密码长度在6-18位", groups = {Insert.class})
    private String password;

    /**
     * 最后一次登录时间
     */
    private LocalDateTime loginTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 创建人主键
     */
    private Long createUserId;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    /**
     * 账户状态 1.正常 0.锁定
     */
    @TableField("status")
    private Integer status;
    /**
     * 用户角色
     */
    @TableField(exist = false)
    private List<SysRole> sysRoleList;
    /**
     * 用户组织
     */
    @TableField(exist = false)
    private List<SysOrg> sysOrgList;
    /**
     * 用户菜单
     */
    @TableField(exist = false)
    private List<SysMenu> sysMenuList;
    /**
     * 用户权限
     */
    @TableField(exist = false)
    private Set<String> permissions;
    /**
     * 用户角色
     */
    @TableField(exist = false)
    private Set<String> roles;

    public boolean isSuperAdmin() {
        return 1L == this.id;
    }
}
